home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / serialio.c < prev    next >
Text File  |  1979-12-31  |  1KB  |  51 lines

  1.  
  2.  
  3.  
  4.     TECHNICAL INFO ON DOING SEND / RECEIVE FOR IBM-PC
  5.  
  6.  
  7. Here are some functions for doing low-level serial io on the IBM PC.
  8.  
  9. struct regval { unsigned int ax,bx,cx,dx,si,di,ds,es; } ;
  10. #define COM1 0
  11. #define COM2 1
  12.  
  13. /*
  14.     send:      send a character to a COM1
  15.  
  16.     returns:
  17.         The value of the character sent or
  18.         EOF if an error occurred
  19. */
  20. send(ch)
  21. char ch;
  22. {
  23. struct regval srv;
  24.  
  25.     srv.ax = 0x100 | (ch & 0xff);        /* ah = 1, al = ch   */
  26.     srv.dx = COM1;                /* select COM1       */
  27.     sysint(0x14,&srv,&srv);            /* send it           */
  28.     if(srv.ax & 0x8000) return EOF;        /* an error occurred */
  29.     return ch;                /* no error occurred */
  30. }
  31.  
  32.  
  33. /*
  34.     recv: wait until a character is ready at COM1 and return it
  35.     Returns: the character received
  36. */
  37. recv()
  38. {
  39. struct regval srv;
  40.  
  41.   do {                        /* try to receive it */
  42.     srv.ax = 0x200;            /* select function   */
  43.     srv.dx = COM1;            /* select COM1       */
  44.     sysint(0x14,&srv,&srv);        /* try to get it     */
  45.      }
  46.    while (srv.ax & 0xff00);        /* it's not ready yet */
  47.    return (srv.ax & 0xff);        /* return the character */
  48. }
  49.  
  50.  
  51.